Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query: fix panic when selecting non-default engine #8050

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

MichaHoffmann
Copy link
Contributor

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

The panic in question:

2025/01/09 08:32:31 http: panic serving [::1]:36354: duplicate metrics collector registration attempted
goroutine 41 [running]:
net/http.(*conn).serve.func1()
	/nix/store/bavnchxi7v6xs077jxv7fl5rrqc3y87w-go-1.23.3/share/go/src/net/http/server.go:1947 +0xbe
panic({0x2862f80?, 0xc0011947e0?})
	/nix/store/bavnchxi7v6xs077jxv7fl5rrqc3y87w-go-1.23.3/share/go/src/runtime/panic.go:785 +0x132
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(0xc000bc23c0, {0xc0011987e0?, 0x4?, 0x2?})
	/home/mhoffmann/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:406 +0x66
github.com/prometheus/prometheus/promql.NewEngine({{0x39cbf80, 0xc000e20b00}, {0x39e42b8, 0xc000bc23c0}, 0x7fffffff, 0x1bf08eb000, {0x0, 0x0}, 0x45d964b800, 0xc000c752a0, ...})
	/home/mhoffmann/go/pkg/mod/github.com/prometheus/[email protected]/promql/engine.go:411 +0xa7e
github.com/thanos-io/thanos/pkg/api/query.(*QueryEngineFactory).GetPrometheusEngine.func1()
	/home/mhoffmann/git/upstream/thanos/pkg/api/query/v1.go:140 +0x85
sync.(*Once).doSlow(0x2972140?, 0xc0011a38c0?)
	/nix/store/bavnchxi7v6xs077jxv7fl5rrqc3y87w-go-1.23.3/share/go/src/sync/once.go:76 +0xb4

It happens if you configure "--query.promql-engine=thanos" and then configure "engine=prometheus" at query time. We will try constructing a new engine lazily and attempt to register same metrics again.

Changes

  • Fix a panic when we select a different engine then the --query.promql-engine option that was configured

Verification

Manual testing

@MichaHoffmann MichaHoffmann force-pushed the mhoffmann/fix-panic-when-selecting-engine branch from 25c708c to 5895510 Compare January 9, 2025 09:30
fpetkovski
fpetkovski previously approved these changes Jan 9, 2025
saswatamcode
saswatamcode previously approved these changes Jan 9, 2025
Copy link
Member

@saswatamcode saswatamcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM minus lint

Fix duplicate metrics registration when selecting non-default engine

Signed-off-by: Michael Hoffmann <[email protected]>
@MichaHoffmann MichaHoffmann dismissed stale reviews from saswatamcode and fpetkovski via 5229ca6 January 9, 2025 10:23
@MichaHoffmann MichaHoffmann force-pushed the mhoffmann/fix-panic-when-selecting-engine branch from 5895510 to 5229ca6 Compare January 9, 2025 10:23
@pull-request-size pull-request-size bot added size/M and removed size/S labels Jan 9, 2025
@MichaHoffmann MichaHoffmann merged commit f250d68 into main Jan 9, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants